<?php
require_once 'application/constant/templatName.php';
require_once 'application/library/controller/gcBasicAction.php';
require_once 'application/modules/login/services/login_services_IndexService.php';

/**
 * login_IndexController
 * @author    Soochow University
 * @version   1.0
 * @exclude   作  成  日：2011/04/07
 */
class login_IndexController extends gcBasicAction{
    
    /**
     * objService
     */
    private $objService;

    /**
     * indexAction
     */
    public function indexAction(){
        //用于改密码什么的
        //var_dump(encryptionHelper::encryptionByAes("1"));
        $this->setPageUrlForQRCode();
        $this->pvSetPageInfo();
        $this->gcView->blnModel = true;
        $this->gcView->render(templatName::INDEX);
    }

    /**
     * loginAction
     */
    public function loginAction(){
        $arrParameter = array();
        $arrParameter["UserId"] = $this->getParam("txtUserId");
        $arrParameter["UserPassword"] = $this->getParam("txtUserPassword");
        $arrParameter["UserPassword"] = encryptionHelper::encryptionByAes($arrParameter["UserPassword"]);
        $strType = $this->getParam("hidType");

        $this->objService=new login_services_IndexService();
        if ($strType == "1") {
            $arrSearchData = $this->objService->pbGetUserInfo($arrParameter);
            if ($arrSearchData) {
                $arrUserData = array();
                $arrUserData[sysConstant::LOGINUSERNO] = $arrSearchData["USER_NO"];
                $arrUserData[sysConstant::LOGINUSERID] = $arrSearchData["USER_ID"];
                $arrUserData[sysConstant::LOGINUSERNAME] = $arrSearchData["NAME"];
                $arrUserData[sysConstant::USER_DISTINGUISH] = $strType;
                $arrUserData[sysConstant::LOGO] = $arrSearchData["LOGO"];
                //权限
                $arrUserData[sysConstant::USERPERMISSIONS] = $arrSearchData["userpermissions"];
                userDataHelper::setUserData($arrUserData);
                var_dump($arrUserData);
                $this->redirect(templatName::INDEX);
                return;
            }
        } else if ($strType == "2") {
            $arrSearchData = $this->objService->pbGetMemberInfo($arrParameter);
            
            if ($arrSearchData) {
                $arrUserData = array();
                $arrUserData[sysConstant::LOGINUSERNO] = $arrSearchData["MEMBER_NO"];
                $arrUserData[sysConstant::LOGINUSERID] = $arrSearchData["MEMBER_ID"];
                $arrUserData[sysConstant::LOGINUSERNAME] = $arrSearchData["MEMBER_NAME"];
                $arrUserData[sysConstant::USER_DISTINGUISH] = $strType;
                $arrUserData[sysConstant::LOGO] = $arrSearchData["LOGO"];
                //权限
                $arrUserData[sysConstant::USERPERMISSIONS] = null;
                userDataHelper::setUserData($arrUserData);
                var_dump($arrUserData);
                //$strUrl = "";沈洁的画面
                //$this->redirect($strUrl);
                return;
            }
        }
        $this->pvSetPageInfo();
        $this->gcView->blnModel = true;
        //错误信息
        $arrMessage[0] = $this->getMessage("ERR-00006");
        $this->setErrorMsg($arrMessage);
        $this->gcView->UserId = $arrParameter["UserId"];

        $this->gcView->render(templatName::INDEX);
    }

    /**
     * pvSetPageInfo
     */
    private function pvSetPageInfo(){
        $this->gcView->title            = $this->getLabel("Login_Login");
        $this->gcView->Login_Staff      = $this->getLabel("Login_Staff");
        $this->gcView->Login_Member     = $this->getLabel("Login_Member");
        $this->gcView->Login_Password   = $this->getLabel("Login_Password");
        $this->gcView->Login_Reset      = $this->getLabel("Login_Reset");
        $this->gcView->Login_Notice     = $this->getLabel("Login_Notice");
        $this->gcView->Login_Forget     = $this->getLabel("Login_Forget");
    }
}
